package com.boluo.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.boluo.business.vo.AuditInfoVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.boluo.common.annotation.Log;
import com.boluo.common.core.controller.BaseController;
import com.boluo.common.core.domain.AjaxResult;
import com.boluo.common.enums.BusinessType;
import com.boluo.business.domain.BusServiceItem;
import com.boluo.business.service.IBusServiceItemService;
import com.boluo.common.utils.poi.ExcelUtil;
import com.boluo.common.core.page.TableDataInfo;

/**
 * 服务项Controller
 * 
 * @author boluo
 * @date 2023-04-08
 */
@RestController
@RequestMapping("/business/ServiceItem")
public class BusServiceItemController extends BaseController
{
    @Autowired
    private IBusServiceItemService busServiceItemService;


    /**
     * 查询服务项列表
     */
    @PreAuthorize("@ss.hasPermi('business:ServiceItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusServiceItem busServiceItem)
    {
        startPage();
        List<BusServiceItem> list = busServiceItemService.selectBusServiceItemList(busServiceItem);
        return getDataTable(list);
    }

    /**
     * 查询服务项列表 (不支持分页)
     */
    @PreAuthorize("@ss.hasPermi('business:ServiceItem:list')")
    @GetMapping("/listServiceItemNoPage")
    public AjaxResult listServiceItemNoPage(BusServiceItem busServiceItem)
    {
        List<BusServiceItem> list = busServiceItemService.selectBusServiceItemList(busServiceItem);
        return AjaxResult.success(list);
    }

    /**
     * 导出服务项列表
     */
    @PreAuthorize("@ss.hasPermi('business:ServiceItem:export')")
    @Log(title = "服务项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusServiceItem busServiceItem)
    {
        List<BusServiceItem> list = busServiceItemService.selectBusServiceItemList(busServiceItem);
        ExcelUtil<BusServiceItem> util = new ExcelUtil<BusServiceItem>(BusServiceItem.class);
        util.exportExcel(response, list, "服务项数据");
    }

    /**
     * 获取服务项详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:ServiceItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(busServiceItemService.selectBusServiceItemById(id));
    }

    /**
     * 新增服务项
     */
    @PreAuthorize("@ss.hasPermi('business:ServiceItem:add')")
    @Log(title = "服务项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BusServiceItem busServiceItem)
    {
        return toAjax(busServiceItemService.insertBusServiceItem(busServiceItem));
    }

    /**
     * 修改服务项
     */
    @PreAuthorize("@ss.hasPermi('business:ServiceItem:edit')")
    @Log(title = "服务项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BusServiceItem busServiceItem)
    {
        return toAjax(busServiceItemService.updateBusServiceItem(busServiceItem));
    }

    /**
     * 上下架服务项
     */
    @PreAuthorize("@ss.hasPermi('business:ServiceItem:saleStatus')")
    @Log(title = "服务项", businessType = BusinessType.UPDATE)
	@PutMapping("/{id}/{saleStatus}")
    public AjaxResult remove(@PathVariable Long id,@PathVariable Integer saleStatus)
    {
        return toAjax(busServiceItemService.updateBusServiceItemSaleStatus(id,saleStatus));
    }

    /**
     * 发布审核时,提供审核数据(服务项,店长,财务)
     */
    @PreAuthorize("@ss.hasPermi('business:ServiceItem:audit')")
    @GetMapping("/queryServiceItemAuditInfo")
    public AjaxResult queryServiceItemAuditInfo(Long id)
    {

        AuditInfoVO auditInfoVO = busServiceItemService.queryServiceItemAuditInfo(id);
        return AjaxResult.success(auditInfoVO);

    }
}
